package com.glela.api.upload.util;

import java.util.concurrent.Callable;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.glela.api.upload.qiniu.http.HttpProtocolHandler;
import com.glela.api.upload.qiniu.http.HttpRequest;
import com.glela.api.upload.qiniu.http.HttpResponse;

public class qryTask implements Callable<HttpResponse>
{
	private HttpRequest request;

	public qryTask(HttpRequest request)
	{
		this.request = request;
	}

	@Override
	public HttpResponse call() throws Exception
	{
		HttpResponse response = HttpProtocolHandler.getInstance().execute(request);
		String jsonResult = response.getStringResult();
		JSONObject result = JSON.parseObject(jsonResult);
		while (!result.getString("code").equals("0")) {
			response = HttpProtocolHandler.getInstance().execute(request);
			jsonResult = response.getStringResult();
			result = JSON.parseObject(jsonResult);
		}
		return response;
	}

	/**
	 * @return the request
	 */
	public HttpRequest getRequest()
	{
		return request;
	}

	/**
	 * @param request
	 *            the request to set
	 */
	public void setRequest(HttpRequest request)
	{
		this.request = request;
	}

}
